<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
		"http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>doh.robot Dialog A11Y Test</title>

		<style>
			@import "../../../util/doh/robot/robot.css";
		</style>

		<!-- required: dojo.js -->
		<script type="text/javascript" src="../../../dojo/dojo.js"
			djConfig="isDebug: true"></script>

		<!-- functions to help test -->
		<script type="text/javascript" src="../helpers.js"></script>

		<script type="text/javascript">
			dojo.require("dijit.robotx");


			dojo.addOnLoad(function(){
				doh.robot.initRobot('../test_Dialog.html');

				doh.register("dijit.Dialog mouse tests (cancel)",[
					{
						name: "open dialog",
						timeout: 4000,
						runTest: function(){
							var d = new doh.Deferred();

							// Open the dialog
							doh.robot.mouseMoveAt("dialog1button", 1000);
							doh.robot.mouseClick({left: true}, 1000);

							doh.robot.sequence(d.getTestCallback(function(){
								doh.t(isVisible("dialog1"), "dialog 1 has been made visible");
								doh.is("name", dojo.global.dijit._curFocus.id, "focus is on the first field");
							}), 1000);

							return d;
						}
					},

					{
						name: "test that other controls on page can't be clicked",
						timeout: 4000,
						runTest: function(){
							var d = new doh.Deferred();

							doh.robot.mouseMoveAt("plainInput", 500);
							doh.robot.mouseClick({left: true}, 1000);

							doh.robot.sequence(d.getTestCallback(function(){
								doh.t(isVisible("dialog1"), "dialog 1 still visible");
								doh.isNot("plainInput", dojo.global.dijit._curFocus && dojo.global.dijit._curFocus.id, "plain input wasn't focused");
							}), 1000);

							return d;
						}
					},

					{
						name: "open date drop down",
						timeout: 4000,
						runTest: function(){
							var d = new doh.Deferred();

							doh.robot.mouseMoveAt("date", 500);
							doh.robot.mouseClick({left: true}, 1000);

							doh.robot.sequence(d.getTestCallback(function(){
								doh.is("date", dojo.global.dijit._curFocus.id, "focus is on the date field");
								doh.is(1, dojo.query(".dijitCalendarContainer").length, "calendar is being shown");
							}), 1000);

							return d;
						}
					},

					{
						name: "close date drop down",
						timeout: 4000,
						runTest: function(){
							var d = new doh.Deferred();

							doh.robot.mouseMove(10, 10, 500);
							doh.robot.mouseClick({left: true}, 1000);

							doh.robot.sequence(d.getTestCallback(function(){
								doh.is(0, dojo.query(".dijitCalendarContainer").length, "calendar has disappeared");
								doh.t(isVisible("dialog1"), "dialog 1 wasn't closed");
							}), 1000);

							return d;
						}
					},

					{
						name: "cancel dialog",
						timeout: 4000,
						runTest: function(){
							var d = new doh.Deferred();

							var button = dojo.query("#dialog1 .dijitDialogCloseIcon")[0];
							doh.robot.mouseMoveAt(button, 500);
							doh.robot.mouseClick({left: true}, 1000);

							doh.robot.sequence(d.getTestCallback(function(){
								doh.t(isHidden("dialog1"), "dialog 1 was closed");
								doh.is("dialog1button", dojo.global.dijit._curFocus.id, "focus returned to button");
							}), 1000);

							return d;
						}
					}
				]);

				doh.register("dijit.Dialog mouse tests (submit)",[
					{
						name: "submit some data",
						timeout: 15000,
						setUp: function(){
							dijit.byId("dialog1").reset();
						},
						runTest: function(){
							var d = new doh.Deferred();

							// Setup handler to catch submitted data
							var data;
							dojo.connect(dijit.byId("dialog1"), "execute", function(vals){
								data = vals;
							});

							// Open the dialog
							doh.robot.mouseMoveAt("dialog1button", 500);
							doh.robot.mouseClick({left: true}, 1000);

							// Enter some info
							doh.robot.mouseMoveAt("name", 2000);
							doh.robot.mouseClick({left: true}, 1000);
							doh.robot.typeKeys("Ted", 500);

							doh.robot.mouseMoveAt("loc", 500);
							doh.robot.mouseClick({left: true}, 1000);
							doh.robot.typeKeys("America", 500);


							// Submit
							doh.robot.mouseMoveAt("ok", 500);
							doh.robot.mouseClick({left: true}, 1000);

							doh.robot.sequence(d.getTestCallback(function(){
								doh.t(isHidden("dialog1"), "dialog 1 was closed on submit");
								doh.t(data, "got submit data");
								doh.is("Ted", data.name, "Name");
								doh.is("America", data.loc, "Location");
							}), 1000);

							return d;
						}
					}
				]);

				doh.run();
			});
		</script>
	</head>
</html>
